# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=haskell-gtk2hs-buildtools
pkgver=0.13.8.3
pkgrel=45
pkgdesc="Tools to build the Gtk2Hs suite of User Interface libraries."
url="https://hackage.haskell.org/package/gtk2hs-buildtools"
license=('GPL2')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-random' 'haskell-hashtables')
makedepends=('alex' 'happy' 'ghc')
provides=('gtk2hs-buildtools')
conflicts=('gtk2hs-buildtools')
replaces=('gtk2hs-buildtools')
source=("https://hackage.haskell.org/packages/archive/gtk2hs-buildtools/${pkgver}/gtk2hs-buildtools-${pkgver}.tar.gz")
sha512sums=('bf419af7698b14347815132aab9d70ccee6d3f17cf3fe55057048c271b7a62bc1321d4f664cbf68ca8fb3107ae65d6a886c928b2caef3eff3e65cecd5e2e5b02')

build() {
    cd gtk2hs-buildtools-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid # --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd gtk2hs-buildtools-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
}
